//
//  LHStatus.swift
//  sina_weibo
//
//  Created by 刘刘海强 on 16/5/13.
//  Copyright © 2016年 chuanzhi. All rights reserved.
//

import UIKit

class LHStatus: NSObject {
    
    //发微博时间
    var created_at: String?
    //微博ID
    var id: Int64 = 0
    //微博内容
    var text: String?
    //微博来源
    var source: String?
    //用户模型
    var user: LHUser?
    //转发微博模型
    var retweeted_status: LHStatus?
    ///  转发数
    var reposts_count: Int = 0
    ///  评论数
    var comments_count: Int = 0
    ///  表态数
    var attitudes_count: Int = 0
    
    //  转发微博配图
    var pic_urls: [LHStatusPictureInfo]?
    
    //kvc构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user" {
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            user = LHUser(dict: dict)
        } else if key == "retweeted_status" {
            guard let dict = value as? [String: AnyObject] else {
                return
            }
            retweeted_status = LHStatus(dict: dict)
        } else if key == "pic_urls" {
            guard let dictArray = value as? [[String: AnyObject]] else {
                return
            }
            
            //创建可变字典
            var tempArray = [LHStatusPictureInfo]()
            for dict in dictArray {
                let picInfo = LHStatusPictureInfo(dict: dict)
                tempArray.append(picInfo)
            }
            pic_urls = tempArray
            
        } else {
            super.setValue(value, forKey: key)
        }
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    

}
